/********************************************/
  // Creation History
  // --------------------------------------------------------------
  //	Company:			HTHK
  //	NAME:				JobServlet.java
  //    Title   :			operate A Job Record such as:Create,Update,Delete
  //	FUNCTION:
  //	BY:					Jet Tao
  //	DATE:				09/12/2003
  // --------------------------------------------------------------
/*********************************************/

package tss.job;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;
import com.ffpc.util.DateFormatter;

import tss.common.DBServlet2;


public class JobServlet
  extends DBServlet2 {

  @Override
protected String perform(  HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
  {
     //New A Form Action
     String action = new String(request.getParameter("formAction"));
     //New A Job Record
     JobBean Job=JobProcess.createBean();

     //Get A Job Record
     Job.setJob_name(request.getParameter("job_name"));
     Job.setComments(request.getParameter("comments"));

     //Deal different operations
     //Insert
      if (action.trim().equalsIgnoreCase("Create"))
      {
        //Set Job's Create Date and Create By
        Job.setCreate_date(DateFormatter.format(this.getDate()));
        Job.setCreate_by(getUser().getUser_name());
        if (JobProcess.insert(this.getConnection(),Job)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure");
      }
      //Update
      else if (action.trim().equalsIgnoreCase("Update"))
      {
        //Set Job's Update Date and Update By
        Job.setUpd_date(DateFormatter.format(this.getDate()));
        Job.setUpd_by(getUser().getUser_name());
        if (JobProcess.update(this.getConnection(), Job) > 0)
          message.setMessage("Save successfully.");
        else
          message.setMessage("Save failure.");
      }
      //Delete
      else if (action.trim().equalsIgnoreCase("Delete"))
        if (JobProcess.delete(this.getConnection(),Job)>0)
            message.setMessage("Delete successfully.");
        else
            message.setMessage("Delete failure.");
      else
            message.setMessage("No action mapped!");

      return "tss/job/JobSearch.jsp";
  }
}


